<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="themes/bootstrap/easyui.css" rel="stylesheet">
<link href="themes/icon.css" rel="stylesheet">
<script type="text/javascript" src="js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="js/easyui-lang-zh_CN.js"></script>

<title>公司管理系统</title>
<style type="text/css">
#form_ul {
	list-style-type: none;
	margin-top: 20px;
}
#form_ul li {
	margin-top: 15px;
}
</style>
</head>
<script type="text/javascript">
	$(function() {
		 //配置自定义验证框
		   $.extend($.fn.validatebox.defaults.rules, {    
			   mobile: {// 验证手机号码
	               validator: function (value) {
	                   return /^(13|15|18|14)\d{9}$/i.test(value);
	               },
	               message: '手机号码格式不正确'
			   },
			   age: {// 验证年龄
	               validator: function (value) {
	                   return /^\d{2}$/i.test(value);
	               },
	               message: '年龄格式不正确'
			   }
			}); 
		$("#reset").click(function() {
			$("#applyform").form('clear');
		});
		//加载修改框
		$('#myinfo').form('load','findmyinfo');
      //个人中心的请假申请确定
		$("#applyAflBtn").click(function() {
				if ($("#startdate").datebox('getValue')&& $("#enddate").datebox('getValue')&& $("#reason").val()) {
					if ($("#reason").val().length>255) {
						$.messager.confirm('提示','请假原因超过字数限制',function(r){    
						    if (r){    
						    }    
						});
					} else {
						//得到输入的时间
						var starttime = new Date($("#startdate").datetimebox('getValue'));
						var endtime = new Date($("#enddate").datetimebox('getValue'));
						var a = (endtime-starttime)/60000;
						//验证结束时间是否大于开始时间
						if (a<0) {
							$.messager.confirm('提示','输入日期有误',function(r){    
							    if (r){    
							    }    
							});
						} else {
							$('#applyform').form('submit',{
								url : '${pageContext.request.contextPath}/employeeApplyAfl',
								success : function(data) {
									if ("1" == data) {
										$.messager.confirm('提示','申请成功',function(r) {
											if (r) {
												$("#applyrecord").dialog('close');
											}
										});

									} else {
										$.messager.alert('提示','申请失败');
									}
								}
							});
						}
					}
						
				} else {
					$.messager.confirm('提示', '请输入完整信息',function(r) {
						if (r) {
						}
					});
				}
			});
		//默认申请请假记录是关闭的
		$('#applyrecord').dialog('close');
		//默认修改密码面板是关闭的
		$('#updatapassword').dialog('close');
		//默认修改个人信息是关闭的
		$('#up').dialog('close');
		//旧密码框的验证
		$('#oldpassword').blur(function(){
			 if($("#oldpassword").val()!='${loginEmployee.e_password}'){
				 $("#tips1").css("display","inline");
				 $('#changepwdbtn').linkbutton('disable');
			} else{
				 $("#tips1").css("display","none");
				 $('#changepwdbtn').linkbutton('enable');
			}
		})
		//验证两次新密码的输入是否一致
		$('#renewpassword').blur(function(){
			 if($("#renewpassword").val()!=$("#newpassword").val()){
				 $("#tips2").css("display","inline");
				 $('#changepwdbtn').linkbutton('disable');
			}else{
				 $("#tips2").css("display","none");
				 $('#changepwdbtn').linkbutton('enable');
			} 
		})
		$("#changepwdbtn").click(function() {
			var newpwd=$("#renewpassword").val();
			$.ajax({
				   type:'post',
				   url:"changepwd?pwd="+newpwd,
				   dataType:"text",
				   success:function(data){
					   if(data=='1'){
						   $.messager.confirm('确认','修改密码成功！',function(r){    
							    if (r){    
							    	$('#updatapassword').dialog('close');
							    }    
							});
					   }else{
						   $.messager.alert('确认','修改密码失败！');
					   }
				   }
			   });
		})

		//显示首页
		$('#showTabs').tabs('add', {
			title : '首页',
			fit : true,
			content : "<div style='width: 100%;height: 100%' >欢迎</div>",

			closable : false,

		});
		//查看个人信息的点击事件
		$("#findmyinfo").click(function() {
							if ($('#showTabs').tabs('exists', '个人信息')) {
								$('#showTabs').tabs('select', '个人信息')
							} else {
								$('#showTabs').tabs('add',{
													title : '个人信息',
													fit : true,
													content : "<iframe style='width: 100%;height: 100%'  src='mycenter/myinfo.jsp'  frameborder='0'></iframe>",
													closable : true,
												});
								var li = top.$(".tabs-wrap ul li:last-child");
								top.$("#close").remove();
								li.after("<li id='close'><a class='tabs-inner' href='javascript:void()' onClick='javascript:closeAll()'>关闭全部</a></li>");
							}
						})
		//修改个人信息的点击事件
		$("#upmyinfo").click(function() {
			$('#up').dialog('open');
		})
		//提交请假申请的点击事件
		$("#applybut").click(function() {
			$('#applyrecord').dialog('open');

		})
		//修改密码的点击事件
		$("#uppassword").click(function(){
			$('#updatapassword').dialog('open');
		})
		//确定修改个人信息的点击事件
		$("#upsure").click(function() {
			$('#myinfo').submit();
		})
		$("#clear").click(function() {
			$('#up').dialog('close');
		})
		//修改表单的的提交
		$('#myinfo').form({
			url : '${pageContext.request.contextPath}/upmyinfo',
			success : function(data) {
				if (data == '1') {
					$.messager.alert('我的消息', '更新成功', 'info', function() {
						$('#up').dialog('close');
						 $.ajax({
							   type:'post',
							   url:"login?enumber=${loginEmployee.e_number}&epassword=${loginEmployee.e_password}",
							   dataType:"text",
							   success:function(data){ 								   
							   }
						   });
					});
				} else {
					$.messager.alert('我的消息', '更新失败');
				}
			}
		});
		//退出的点击事件
		$("#exit").click(function() {
			location.href = "login.jsp";
		})
		//树形菜单配置
		$("#showFuncs").tree({
			url : 'showfuncs',
			onLoadSuccess : function(node, data) {
				$("#showFuncs").tree('expandAll');
			}
		})

		//点击左边功能右边显示tab框
		$('#showFuncs').tree({
							onClick : function(node) {
								if (node.attributes.fpath)
									if ($('#showTabs')
											.tabs('exists', node.text)) {
										$('#showTabs')
												.tabs('select', node.text)
									} else {
										$('#showTabs').tabs('add',{
															title : node.text,
															fit : true,
															content : "<iframe style='width: 100%;height: 100%'  src='"
																	+ node.attributes.fpath
																	+ "'  frameborder='0'></iframe>",
															closable : true,
														});
										var li = $(".tabs-wrap ul li:last-child");
										$("#close").remove();
										li.after("<li id='close'><a class='tabs-inner' href='javascript:void()' onClick='javascript:closeAll()'>关闭全部</a></li>");
									}
							}
						});

		$('#showTabs').tabs({
			fit : true

		});

	})
	//关闭所有的tabs框
	function closeAll() {
		$(".tabs li").each(function(index, obj) {
			//获取所有可关闭的选项卡  
			var tab = $(".tabs-closable", this).text();
			$(".easyui-tabs").tabs('close', tab);
		});

		$("#close").remove();//同时把此按钮关闭  
	}
	//每隔10分钟判断是否有未处理的请假消息
	setInterval(function() {
		$.ajax({
			url : '${pageContext.request.contextPath}/isExistAflApply',
			type : 'post',
			dataType : 'text',
			success : function(data) {
				if (data == "1") {
					$.messager.show({
						title : '提示',
						msg : '有请假申请未处理',
						timeout : 0,
						showType : 'slide'
					});
				}
			}
		});
	}, 1000 * 60 * 10);
	//每隔5秒判断是否有新的请假申请
	setInterval(function() {
		$.ajax({
			url : '${pageContext.request.contextPath}/hasApplyAfl',
			type : 'post',
			dataType : 'text',
			success : function(data) {
				if (data == "1") {
					$.messager.show({
						title : '提示',
						msg : '有新的请假申请啦',
						timeout : 0,
						showType : 'slide'
					});
				} else if (data == "2") {
					$.messager.show({
						title : '提示',
						msg : '你的请假申请已同意',
						timeout : 0,
						showType : 'slide'
					});
				} else {

				}
			}
		});
	}, 5000);
</script>
<body id="main" class="easyui-layout">
	<div data-options="region:'north'" style="height: 100px;">
		${loginEmployee.e_name},欢迎你！<a style="margin-left: 1200px" href="#"
			class="easyui-menubutton"
			data-options="menu:'#mm1',iconCls:'icon-man'">个人中心</a>
	</div>
	<div data-options="region:'west',title:'功能区域',collapsible:true"
		style="width: 250px;">
		<!-- 菜单展示 -->
		<ul id="showFuncs"></ul>
	</div>
	<div data-options="region:'center'"
		style="padding: 5px; background: #eee;">

		<div id="showTabs" class="easyui-tabs"
			style="width: 100%; height: 100%;"></div>


	</div>

	<div id="mm1" style="width: 150px;">
		<div class="menu-sep"></div>
		<div data-options="iconCls:'icon-search'">
			<a id="findmyinfo">查看个人信息</a>
		</div>
		<div data-options="iconCls:'icon-edit'">
			<a id="upmyinfo">修改个人信息</a>
		</div>
		<div data-options="iconCls:'icon-edit'">
			<a id="uppassword">修改密码</a>
		</div>
		<div data-options="iconCls:'icon-edit'">
			<a id="applybut">申请请假</a>
		</div>
		<div class="menu-sep"></div>
		<div data-options="iconCls:'icon-cancel'">
			<a id="exit">退出登录</a>
		</div>
	</div>
	<!-- 修改密码面板 -->
	<div id="updatapassword" class="easyui-dialog" title="修改密码"
		style="width: 600px; height: 470px;" data-options="modal:true">
		<form id="uppwdform" method="post">
			<br> <br>
			
				<center>请输入旧密码：<input id="oldpassword" type="password"  name="oldpwd"><span id="tips1" style="display: none;font-size: 10px;color: red">旧密码错误</span></center>
				<br>
				<br>
				<br>
				<center>请输入新密码:<input id="newpassword" type="password" name="newpwd"></center>
				<br>
				<br>
				<br>
			    <center>请再次输入新密码:<input id="renewpassword" type="password" name="renewpwd"><span id="tips2" style="display: none;font-size: 10px;color: red">两次密码输入不一致</span></center>
			     <br>
			     <br>
			     <br>
			   <center><a id="changepwdbtn"  class="easyui-linkbutton" data-options="iconCls:'icon-edit '">提交</a> 
			      <a id="changepwdcancle"  class="easyui-linkbutton" data-options="iconCls:'icon-cancle'">取消</a> 
			     </center>
			</form>
	<!-- 修改个人信息的面板 -->
	<div id="up" class="easyui-dialog" title="修改个人信息"
		style="width: 600px; height: 470px;" data-options="modal:true">
		<form id="myinfo" method="post">
			<br> <br>
			<center>
				<span><input style="display: none" name="e_number"
					>姓名:<input
					readonly="readonly" style="border: none" name="e_name"
					> 性别:<input
					readonly="readonly" style="border: none" name="e_sex"
					></span>
			</center>
			<br> <br> <br>
			<center>
				<span>年龄:<input class="easyui-textbox"
					data-options="required:true,validType:'age',missingMessage:'年龄必填'" name="e_age"
					>联系电话:<input
					class="easyui-textbox"
					data-options="required:true,validType:'mobile',missingMessage:'联系电话必填'" name="e_tel"
					></span>
			</center>
			<br> <br> <br>
			<center>
				<span>邮箱:<input class="easyui-textbox"
					data-options="required:true,validType:'email',missingMessage:'邮箱必填'" name="e_email"
					> 地址:<input
					class="easyui-textbox"
					data-options="required:true,missingMessage:'地址必填'" name="e_address"
					></span>
			</center>
			<br> <br> <br>
			<center>
				<span>出生日期:<input
					data-options="required:true,missingMessage:'出生日期必填'"
					class="easyui-datebox" 
					name="e_birthday" style="width:100px"></span>
			</center>
			<br> <br> 
			<center>
				<span>个人描述:<input style="width:200px; height: 60px"
					class="easyui-textbox"
					data-options="required:true,missingMessage:'个人描述必填'"
					name="e_description" ></span>
			</center>
			<br><br>			
		</form>
		<center>
				<button id="upsure" type="button">确定</button>
				<button id="clear" type="button">取消</button>
			</center>
	</div>
	<!-- 提交请假申请的panel -->
	<div id="applyrecord" class="easyui-dialog" title="请假申请"
		style="width: 400px; height: 250px;" data-options="modal:true">
		<form id="applyform" method="post">
			<ul id="form_ul">
				<li>
					<div>
						<label>请假日期</label> <input type="text" class="easyui-datebox"
							id="startdate" name="startdate" data-options="required:true"
							style="width: 34%">~ <input type="text"
							class="easyui-datebox" id="enddate" name="enddate"
							data-options="required:true" style="width: 34%">
					</div>
				</li>
				<li>
					<div>
						<label>请假原因</label> <input type="text" class="easyui-textbox"
							id="reason" name="reason"
							data-options="required:true,multiline:true,prompt:'请输入请假原因（限80字）'"
							style="width: 70%; height: 60px;">
					</div>
				</li>
			</ul>
		</form>
		<div style="margin-top: 20px; text-align: center;">
			<input type="button" id="applyAflBtn" value="申请"
				style="width: 100px;"> <input type="button" id="reset"
				value="重置" style="width: 100px; margin-left: 10px">
		</div>
	</div>

</body>
</html>